<?php
/**
 * Plugin to authorise user against ACL rules.
 *
 * @category Zend
 * @package Acl
 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc.
 * @version $Id$
 * @link http://framework.zend.com
 * @since Available since release 1.0
 */

final class Disputeo_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
    /**
     * Setup view and request properties
     * 
     * @param Zend_Controller_Request_Abstract $request 
     */
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $session = Disputeo_Session::getSession();
        $acl = Zend_Registry::get('acl');
        $resource = $request->getControllerName();
        $privilage = $request->getActionName();
        
        if (! $acl->has($resource)) {
            return true;
        }
        
        if (! $acl->isAllowed($session->usertype, $resource, $privilage)) {
            $request->setControllerName('error');
            $request->setActionName('index');
        }
    }
}